<?php

namespace App\Console\Commands;

use App\Export\ComboOrderExport;
use App\Http\Controllers\Admin\Business\Service\ComboOrder;
use App\Mail\SendOrder;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Mail;
use Maatwebsite\Excel\Facades\Excel;

class SendEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'email:send';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '发送当前一天内的支付订单';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $comboOrder= new ComboOrder();
        $cellData=$comboOrder->exportList1(['start_time'=>Carbon::yesterday(),'end_time'=>Carbon::today()]);
        $filename=Carbon::yesterday().'~'.Carbon::today().'支付订单'.rand(1,10);
        Excel::create($filename,function($excel) use ($cellData){
            $excel->sheet('orders', function($sheet) use ($cellData){
                $sheet->rows($cellData);
            });
        })->store('xls');
        Mail::to('736400469@qq.com')->send(new SendOrder($filename));
        Mail::to('xyt_lujiagang@163.com')->send(new SendOrder($filename));
    }
}
